/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.totoBD.gui.swing.components.table;

import com.totoBD.gui.swing.components.combobox.CmbMysqlVaTypes;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author rgil
 */
public class TblTableCreate extends JTable{


    public TblTableCreate(){


            this.setModel(
                new DefaultTableModel(
                    this.data,
                    this.columnNames
                ));

        this.count = 1;


this.initialiseTable();

    }
    public void initialiseTable()
    {
        JComboBox comboBox = new CmbMysqlVaTypes();
        JTextField txf = new JTextField();
        txf.setEnabled(false);
        this.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(txf));

this.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(comboBox));
    TableColumn column = null;
    for (int i = 0; i < 2; i++) {
        column = this.getColumnModel().getColumn(i);
        if (i == 1) {
            column.setPreferredWidth(250);
        } else {
            column.setPreferredWidth(50);
        }
    }
    }

    public void appendRow(){
        this.count = this.count+1;
        int intCol = 2;
        Object[][] objssNew = new Object[this.count][intCol];


        for (int i = 0; i <count-1; ++i)    {
        for (int j = 1 ; j < intCol; ++j){
            
                System.out.println(_objssData[i][j]);
                objssNew[i][j] = this._objssData[i][j];
            }
             objssNew[i][0]=i+1;
        }
        for (int j = 1 ; j < intCol; ++j){
            objssNew[count-1][j] = null;
        }
        objssNew[count-1][0]=count;
        _objssData=objssNew;
        //fireTableRowsInserted(intRowCountNew-1, intRowCountNew-1);
        this.setModel(
            new DefaultTableModel(
                this._objssData,
                this.columnNames
            )
        );
        this.initialiseTable();
}


        Object[][] data = {{null, null, null}};

    String[] columnNames = {
        "Field ID",
        "Field name",
        "Field type"};

        int count;
    private Object[][] _objssData = {{null, null, null}};
    private Object[] defaultRow = {null, null, null};
}
